package com.baosight.sczx.zm.cd.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiBlockMeta;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.ef.ui.tree.TreeConstants;
import com.baosight.iplat4j.ef.ui.tree.TreeService;
import com.baosight.iplat4j.ep.QueryMap;

/**
 * <p>Title: ServiceZMCD10.java</p>
 * <p>Description: 目录管理的树</p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 张志芳
 * @version 1.0
 * <pre>Histroy:
 *          2011-8-24 下午05:09:27  张志芳  Create
 *</pre>
 */
public class ServiceZMCD10 extends TreeService {

	private static String topPublicNodeId = "public";//公用目录
	private static String topSpecialNodeId = "special";//特殊目录
	
	@SuppressWarnings("rawtypes")
	public EiInfo query(EiInfo inInfo) {
		QueryMap queryInfo = QueryMap.getQueryMap(inInfo);
		String p = (String) queryInfo.get(TreeConstants.TREE_NODE);
		List children = new ArrayList();
		if (p == null) {
			p = "$";
		}
		if ("$".equals(p)) {
			children = this.getTopNodes();
		} else {
			children = this.getChildNodes(p);
		}

		EiInfo outInfo = new EiInfo();
		EiBlock block = outInfo.addBlock(p);
		block.setBlockMeta(initMetaData());
		block.setRows(children);
		return outInfo;
	}
	/**
	 * <p>Function: getChildNodes</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCD10</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-8-24下午05:09:27 张志芳
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	@Override
	public List getChildNodes(String args) {
		String[] ps=args.split("-");
		Map<String, String> _argMap = new HashMap<String, String>();
		_argMap.put(TreeConstants.TREE_NODE, ps[0]);
		
		List<?> childNodes = dao.query("ZMCDDirectory.treeNodes1", _argMap);
		return childNodes;
	}

	/**
	 * <p>Function: getTopNodes</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCD10</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-8-24下午05:09:27 张志芳
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	@Override
	public List getTopNodes() {
		List<Map<String, String>> _topNodes = new ArrayList<Map<String, String>>();
		
		Map<String, String> _tempMap = new HashMap<String, String>();
		_tempMap.put("label", topPublicNodeId+"-"+"公用目录");
		_tempMap.put("type", "公用目录");
		_tempMap.put("text", "公用目录");
		_tempMap.put("leaf", "0");
		_topNodes.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", topSpecialNodeId+"-"+"指定目录");
		_tempMap.put("type", "指定目录");
		_tempMap.put("text", "指定目录");	
		_tempMap.put("leaf", "0");			
		_topNodes.add(_tempMap);
		
		return _topNodes;
	}

	/**
	 * <p>Function: initMetaData</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCD10</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-8-24下午05:09:27 张志芳
	 * </p>
	 *
	 */
	@Override
	public EiBlockMeta initMetaData() {
		EiBlockMeta eiMetadata = new EiBlockMeta();

		EiColumn eiColumn = new EiColumn("label");
		eiColumn.setDescName("label");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);

		eiColumn = new EiColumn("text");
		eiColumn.setDescName("text");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);

		eiColumn = new EiColumn("type");
		eiColumn.setDescName("type");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);

		eiColumn = new EiColumn("leaf");
		eiColumn.setDescName("leaf");
		eiColumn.setType(EiConstant.COLUMN_TYPE_NUMBER);
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);
		return eiMetadata;
	}

}
